<?php
require_once(dirname(dirname(__FILE__)) . '/app.php');

check_login();

$order_id = intval($_POST['order_id']);
$name = trim($_POST['name']);
$mobile = trim($_POST['mobile']);
$adinfo = trim($_POST['adinfo']);
$province = trim($_POST['province']);
$city = trim($_POST['city']);
$area = trim($_POST['area']);


$up_sql = "update address set `default` = 'N' where user_id = {$login_user_id}";
DB::Query($up_sql);

$addr_data = array();
$addr_data['user_id'] = $login_user_id;
$addr_data['province'] = $province;
$addr_data['city'] = $city;
$addr_data['area'] = $area;
$addr_data['street'] = $adinfo;
$addr_data['name'] = $name;
$addr_data['mobile'] = $mobile;
$addr_data['default'] = 'Y';
$addr_data['zipcode'] = '';
$addr_data['create_time'] = time();
$addr_id  = DB::Insert('address', $addr_data);
$id = $addr_id;


Table::UpdateCache('order', $order_id, array(
				'realname' => $name,
				'mobile' => $mobile,
				'address' => $province.$city.$area,
				));
$result = array('state' => false);
if($id)
{
$result['state'] = true;
} 

echo json_encode($result);	
die();
				
				